<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
  <el-input type="text" placeholder="姓名" style="width: 150px" v-model="emp.name"></el-input>
  <el-input type="text" placeholder="工资" style="width: 150px" v-model="emp.salary"></el-input>
  <el-input type="text" placeholder="工作" style="width: 150px" v-model="emp.job"></el-input>
  <el-button type="button" value="添加" @click="add()">添加</el-button>
  <h3>员工列表</h3>
    <el-table :data="arr" style="width: 100%">
      <el-table-column type="index" label="编号"></el-table-column>
      <el-table-column prop="name" label="姓名" width="180"></el-table-column>
      <el-table-column prop="salary" label="工资" width="280"></el-table-column>
      <el-table-column prop="job" label="职位"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
                  size="mini"
                  type="danger"
                  @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
  let v = new Vue({
    el: '#app',
    data: function () {
      return {
        emp: {name:"",salary:"",job:""},
        arr:[]
      }
    },
    methods: {
      handleDelete(i,emp){
        if (confirm("您确定删除吗"+emp.name+"吗?")){
          v.arr.splice(i,1);
          v.$message.success("删除成功!");
        }
      },
      add(){
        let newEmp = {name:v.emp.name,salary:v.emp.salary,job:v.emp.job};
        v.arr.push(newEmp);
      }
    }
  })
</script>
</html>